package cn.biwysh.exam.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.biwysh.exam.biz.ExamBiz;
import cn.biwysh.exam.entity.Exam;

public class khdetail extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{

		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		String url="../WEB-INF/jsp/gl/khdetail.jsp";
		String idstr = request.getParameter("id");
		int nid=0;
		try{
			nid=Integer.parseInt(idstr);
		}catch (Exception e) {
		}
		if(nid>0){
			ExamBiz biz=new ExamBiz();
			Exam exam=biz.GetExamById(nid);
			if(exam!=null){
				request.setAttribute("exam", exam);
				request.setAttribute("maxscore", biz.GetMaxScore(nid));
				request.setAttribute("minscore", biz.GetMinScore(nid));
				request.setAttribute("total", biz.GetScoreDataCount(" and (state!=2 or (state=2 and ADDTIME(addtime, '02:05:00')<current_timestamp()))  and eid="+nid));
				Date now=new Date();
				//now.setYear(now.getYear()+1900);
				//System.out.println(now.toString());
				if(exam.getStarttime().before(now)){
					request.setAttribute("examstart", true);
				}else{
					request.setAttribute("examstart", false);
				}
			}else {
				url="khgl.do?page=khlist";
			}
			
		}else{
			url="khgl.do?page=khlist";
		}
		RequestDispatcher requestDispatcher = request.getRequestDispatcher(url);
		requestDispatcher.forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{

		this.doGet(request, response);
	}

}
